using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.CompositeUI;
using LibrErian.Interfaces.Data;
using Microsoft.Practices.CompositeUI.SmartParts;

namespace LibrErian.Common
{
    public class Presenter<ViewType> : Controller 
    {
        private ViewType view;
        private IDataManager dataManager;

        public ViewType View
        {
            get 
            { 
                return view; 
            }
            set 
            { 
                view = value; 
            }
        }

        [ServiceDependency]
        public IDataManager DataManager
        {
            set 
            { 
                dataManager = value; 
            }

            protected get
            {
                return dataManager;
            }
        }


        public virtual void CloseView()
        {
            IWorkspaceLocatorService locator = WorkItem.Services.Get<IWorkspaceLocatorService>();
            IWorkspace wks = locator.FindContainingWorkspace(WorkItem, View);
            if (wks != null)
                wks.Close(View);
        }

        public virtual void OnViewReady() { }
    }
}
